package demo523;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class TestConnection {
    private static final String URL = "jdbc:mysql://localhost/usersDb";

    private static final String USERNAME = "root";

    private static final String PASSWORD = "123456";
    public static void main(String[] args)throws SQLException,  ClassNotFoundException {{
        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入用户名");
        String username = scanner.nextLine();

        System.out.print("请输入密码");
        String password = scanner.nextLine();
        Class.forName("com.mysql.jdbc.Driver");
        Connection connection= DriverManager.getConnection(URL, USERNAME, PASSWORD);
        String  sql = "insert into users(username,password) values(?,?) ";
        PreparedStatement preparedStatement = connection.prepareStatement(sql);
        preparedStatement.setString(1, username);
        preparedStatement.setString(2, password);

        int i=preparedStatement.executeUpdate();
        if (i>0){
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败");
        }

    }

    }

}
